<!DOCTYPE html>
<html>
<head>
    <title>作业1</title>
</head>
<body>
<h1>表单提交demo</h1>

<!-- 页面表单  post -->
<h4>POST请求表单</h4>
<form method="post" action="work1.php">
    <label for="name">姓名:</label>
    <input type="text" id="name" name="name" required><br><br>
    <label for="age">年龄:</label>
    <input type="number" id="age" name="age" required><br><br>
    <input type="submit" value="提交">
</form>

<!-- 页面表单  get -->
<hr/>
<h4>get请求表单</h4>
<form method="get" action="work1.php">
    <label for="name1">姓名:</label>
    <input type="text" id="name1" name="name" required><br><br>
    <label for="age1">年龄:</label>
    <input type="number" id="age1" name="age" required><br><br>
    <input type="submit" value="提交">
</form>

<!-- 请求处理 -->
<?php
// 检查是否有 POST 请求发送到该页面
    // 获取表单提交的数据
    $name = htmlspecialchars($_POST["name"]);
    $age = $_POST["age"];

    echo "<h2>post请求接收到的数据：</h2>";
    echo "姓名: " . $name . "<br>";
    echo "年龄: " . $age . "<br>";


    $name1 =  htmlspecialchars($_GET["name"]);
    $age1 = $_GET["age"];

    echo "<h2>get请求接收到的数据：</h2>";
    echo "姓名: " . $name1 . "<br>";
    echo "年龄: " . $age1 . "<br>";

?>
</body>
</html>